﻿// owner 蒋家伟

#pragma once
#include "Device_home.h"
#include <functional>

namespace jsdk
{
    class IDevice;

    // 构造设备的函数
    using DeviceCreatorFunc = std::function<OwnerPtr<IDevice>()>;

    // 设备注册助手
    class DEVICE_EXPORT IDeviceRegisterHelper
    {
    public:
        virtual ~IDeviceRegisterHelper() {}

        /// \ 获取设备注册助手
        /// \ return  IDeviceRegisterHelper
        static IDeviceRegisterHelper* get();

        /// \ 注册设备
        /// \ in creator 构造设备的函数
        virtual bool registerCreator(DeviceCreatorFunc creator) = 0;
    };
}

#define DEVICE_REGISTER(CLASS_NAME, DEVICE_CREATOR_FUNC) \
    bool global_##CLASS_NAME = IDeviceRegisterHelper::get()->registerCreator(CLASS_NAME :: DEVICE_CREATOR_FUNC);
